<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var rg = /abc/; //正则表达式内不用加引号
        console.log(rg.test('abc')); //只要包含abc字符串就返回true
        console.log(rg.test('abcd'));
        console.log(rg.test('aabc'));

        console.log('-----------------------------');
        var rge = /^abc/;//^表示必须以abc字符串开头
        console.log(rge.test('abc'));
        console.log(rge.test('abcd'));
        console.log(rge.test('aabc'));

        console.log('-----------------------------');
        var re = /^abc$/; //同理$表示必须以abc字符串开头  同时使用可以精确匹配
        console.log(re.test('abc'));
        console.log(re.test('abcd'));
        console.log(re.test('aabc'));

    </script>
</body>

</html>